package org.altoro.consumer;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.altoro.trongeventquery.transactions.TransactionTriggerEntity;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.support.Acknowledgment;

import java.util.List;

/**
 * @Auther: little liu
 * @Date: 2020/10/23/15:17
 * @Description:
 */
@Slf4j
//@Component
public class TransactionTriggerConsumer {

//    @KafkaListener(topics = "transaction", containerFactory = "kafkaListenerContainerFactory")
    public void onTransactionTrigger(List<ConsumerRecord<String, String>> records, Acknowledgment ack) {
        ack.acknowledge();
        for (int i = 0; i < records.size(); i++) {
            ConsumerRecord<String, String> record = records.get(i);
            String key = record.key();
            TransactionTriggerEntity transactionTrigger = JSON.parseObject(record.value(), TransactionTriggerEntity.class);
            log.info("key:{},transactionTrigger:{}",key,transactionTrigger);
        }
    }

}
